/*
 * @Author: wangwei wwdqq7@qq.com
 * @Date: 2025-04-01 15:35:00
 * @LastEditors: wangwei wwdqq7@qq.com
 * @LastEditTime: 2025-04-01 15:35:00
 * @FilePath: /FullStack/pro/typeorm-mysql/src/dto/access.dto.ts
 * @Description: 访问权限DTO，定义表级和数据库级权限管理相关请求和响应的数据结构
 */
import { ApiProperty } from '@nestjs/swagger';

import { PermissionResponseDto } from '@/dto/permission.dto';

// 表级权限DTO
export class TableAccessDto {
  @ApiProperty({
    description: '权限ID',
    example: 1,
    required: true,
  })
  permissionId: number;

  @ApiProperty({
    description: '数据库名称',
    example: 'mydb',
    required: true,
  })
  databaseName: string;

  @ApiProperty({
    description: '表名称',
    example: 'users',
    required: true,
  })
  tableName: string;
}

// 数据库级权限DTO
export class DatabaseAccessDto {
  @ApiProperty({
    description: '权限ID',
    example: 1,
    required: true,
  })
  permissionId: number;

  @ApiProperty({
    description: '数据库名称',
    example: 'mydb',
    required: true,
  })
  databaseName: string;
}

// 权限检查DTO
export class PermissionCheckDto {
  @ApiProperty({
    description: '用户ID',
    example: 1,
    required: true,
  })
  userId: number;

  @ApiProperty({
    description: '数据库名称',
    example: 'mydb',
    required: true,
  })
  databaseName: string;

  @ApiProperty({
    description: '表名称',
    example: 'users',
    required: false,
  })
  tableName?: string;

  @ApiProperty({
    description: '操作类型',
    example: 'SELECT',
    enum: ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'ALTER'],
    required: true,
  })
  action: string;
}

// 表级权限响应DTO
export class TableAccessResponseDto {
  @ApiProperty({
    description: '用户ID',
    example: 1,
  })
  userId: number;

  @ApiProperty({
    description: '权限',
    type: PermissionResponseDto,
  })
  permission: PermissionResponseDto;

  @ApiProperty({
    description: '数据库名称',
    example: 'mydb',
  })
  databaseName: string;

  @ApiProperty({
    description: '表名称',
    example: 'users',
  })
  tableName: string;
}

// 数据库级权限响应DTO
export class DatabaseAccessResponseDto {
  @ApiProperty({
    description: '用户ID',
    example: 1,
  })
  userId: number;

  @ApiProperty({
    description: '权限',
    type: PermissionResponseDto,
  })
  permission: PermissionResponseDto;

  @ApiProperty({
    description: '数据库名称',
    example: 'mydb',
  })
  databaseName: string;
}

// 权限检查响应DTO
export class PermissionCheckResponseDto {
  @ApiProperty({
    description: '是否有权限',
    example: true,
  })
  hasPermission: boolean;

  @ApiProperty({
    description: '权限来源',
    example: 'role',
    enum: ['role', 'direct', 'none'],
  })
  source: string;
}
